<#include "include/_meta.html">
<!--/meta 作为公共模版分离出去-->

<title>会员等级级管理</title>
<meta name="keywords" content="汽车租赁">
<meta name="description" content="汽车租赁">
</head>
<body>
	<nav class="breadcrumb">
	<i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 系统管理 <span class="c-gray en">&gt;</span> 会员级别 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
		<div class="cl pd-5 bg-1 bk-gray mt-20"> 
			<span class="l">
				<a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> 
				<a href="javascript:;" onclick="grade_add('添加会员级别','/gradeadd','800','500')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加会员级别</a>
			</span> 
			<span class="r">共有数据：<strong id="pageTotal">54</strong> 条</span>
		 </div>
		 
		<div class="page-container">
			<table id="gradeListTable" class="table table-border table-bordered table-bg table-hover">
				<thead>
					<tr class="text-c">
						<th><input type="checkbox" name="gradeId"></th>
						<th>编号</th>
						<th>会员级别</th>
						<th>信用值最小积分</th>
						<th>信用值最大积分</th>
						<th>租车折扣</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
					
				</tbody>
			</table>
	
		</div>
<!--_footer 作为公共模版分离出去--> 
<#include "include/_footer.html">
<!--/_footer /作为公共模版分离出去--> 
<!--请在下方写此页面业务相关的脚本--> 
<script type="text/javascript">

	$(function(){
		initTable();
	});
	
	//查询会员等级所有信息
	var initTable = function(){
		$("#gradeListTable").dataTable({
      		"processing": false,
      		"serverSide": true,
      		"bSort": false,
      		"bFilter":false,
      		"bLengthChange":false,
      		"iDisplayLength":10,
      		"bRetrieve":true,
      		"ajax": {
           		"url": "/grades",
            	"type": "get"
        },
        "columns": [
            { "data": "" },
            { "data": "levelId" },
            { "data": "levelName" },
            { "data": "minScore" },
            { "data": "maxScore" },
            { "data": "discount" },
            { "data": "" }
      	],
      	"columnDefs": [
	        {
		          "targets": [0],
		          "data": "id",
		          "render": function(data, type, full) {
		            return "<input type='checkbox' value=" + full.levelId + " name='gradeId'>";
		            //return full.id+"";
		          }
	        },
	        {
		          "targets": [6],
		          "data": "id",
		          "render": function(data, type, full) {
		          		var action_look = "<a style='text-decoration:none' onClick=\"grade_look('会员详细信息','/gradeget?id="+full.levelId+"','2','800','500')\" href=\"javascript:;\" title=\"详情\"><i class=\"Hui-iconfont\">&#xe665;</i></a>";
		          		var action_edit    = "<a title=\"编辑\" href=\"javascript:;\" onclick=\"grade_edit('会员等级编辑','/gradeedit?id="+full.levelId+"','2','800','500')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6df;</i></a>";
		          		var action_del     = "<a title=\"删除\" href=\"javascript:;\" onclick=\"grade_del(this,'"+full.levelId+"')\" class=\"ml-5\" style=\"text-decoration:none\"><i class=\"Hui-iconfont\">&#xe6e2;</i></a>";
		        
		            	return action_look+" "+action_edit+" "+action_del;
		          }
	        }	        
      	],
      	"fnRowCallback" : function(nRow, aData, iDisplayIndex) { 
      					nRow.className="text-c";         
                        $('td:eq(1)', nRow).html(iDisplayIndex+1);                   
                        return nRow;  
         },
      	"fnDrawCallback": function(oSettings) {
		      //获取后台方式 直接可以拿到json 之后进行处理
		      var json=jQuery.parseJSON(oSettings.jqXHR.responseText);  
		      $("#pageTotal").html(json.recordsTotal);
	    }
		});
	}
	
	
	
	var datadel = function(){
	
	//判断选择项是否为空
	var checkedNum = $("input[name='gradeId']:checked").length;
	if(checkedNum==0){
		layer.msg('请选中要删除的列表项!',{icon: 5,time:1000});
		return;
	}
	//获取选择项的值
	var checkedVal = "";
	$("input[name='gradeId']:checked").each(function(){  
		checkedVal+=$(this).val()+",";  
	});
	
	var itemsTipStr = "这条记录";
	if(checkedNum>1){
		itemsTipStr = "这些选项";
	}
	
	layer.confirm('确认要删除'+itemsTipStr+'吗？',function(){
	
		//此处请求后台程序，下方是成功后的前台处理……
		$.ajax({
		   type: "POST",
		   url: "/deletegrades",
		   data: "levelIds="+checkedVal,
		   success: function(msg){
		   		   
				layer.msg('已删除!',{icon: 5,time:1000});
				
				$("#gradeListTable").dataTable().fnClearTable();
		        initTable();
		   }
		});
		

        
	});
	
	
}
	
	
	
	
	
	

	//添加会员等级
	function grade_add(title,url,w,h){
		layer_show(title,url,w,h);
	}
	
	/*会员等级-编辑*/
	function grade_edit(title,url,id,w,h){
		layer_show(title,url,w,h);
	}
	
	/*会员等级-删除*/
	function grade_del(obj,id){
		layer.confirm('确认要删除吗？',function(index){
			//此处请求后台程序，下方是成功后的前台处理……
			
			
			$.ajax({
			   type: "POST",
			   url: "/deletegrade",
			   data: "id="+id,
			   success: function(msg){
			       	$("#gradeListTable").dataTable().fnClearTable();
	        		initTable();
			   }
			});
			
			
			$(obj).parents("tr").remove();
		layer.msg('已删除!',{icon:1,time:1000});
		});
	}
	
	/*查看会员等级详细信息*/
	function grade_look(title,url,id,w,h){
		layer_show(title,url,w,h);
	}

</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>